import JSEncrypt from 'jsencrypt';

// console.log(jsencrypt);

// const { JSEncrypt } = jsencrypt;

// 密钥对生成 http://web.chacuo.net/netrsakeypair

// const publicKey = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKoR8mX0rGKLqzcWmOzbfj64K8ZIgOdH\n' +
//   'nzkXSOVOZbFu/TJhZ7rFAN+eaGkl3C4buccQd/EjEsj9ir7ijT7h96MCAwEAAQ=='

const publicKey =
  'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQClVZNhqfOKBnasYPhRy0jRHUF6z09wdnxA5Hg53Xeqn78ZEubNVmIP+w2mIRixLYsvxbKSlPJnqTRlK57OZDJkDL4xJ/elFVJ9vQE+QnmVvd3YTlmOCF2oo2GYFOadPMliZv84xg0VVwAqp9zeufp5QbtuSh8DZreH2gI72acb6wIDAQAB';

// const privateKey = 'MIIBVAIBADANBgkqhkiG9w0BAQEFAASCAT4wggE6AgEAAkEAqhHyZfSsYourNxaY\n' +
//   '7Nt+PrgrxkiA50efORdI5U5lsW79MmFnusUA355oaSXcLhu5xxB38SMSyP2KvuKN\n' +
//   'PuH3owIDAQABAkAfoiLyL+Z4lf4Myxk6xUDgLaWGximj20CUf+5BKKnlrK+Ed8gA\n' +
//   'kM0HqoTt2UZwA5E2MzS4EI2gjfQhz5X28uqxAiEA3wNFxfrCZlSZHb0gn2zDpWow\n' +
//   'cSxQAgiCstxGUoOqlW8CIQDDOerGKH5OmCJ4Z21v+F25WaHYPxCFMvwxpcw99Ecv\n' +
//   'DQIgIdhDTIqD2jfYjPTY8Jj3EDGPbH2HHuffvflECt3Ek60CIQCFRlCkHpi7hthh\n' +
//   'YhovyloRYsM+IS9h/0BzlEAuO0ktMQIgSPT3aFAgJYwKpqRYKlLDVcflZFCKY7u3\n' +
//   'UP8iWi1Qw0Y='

const privateKey =
  'MIICeQIBADANBgkqhkiG9w0BAQEFAASCAmMwggJfAgEAAoGBAKVVk2Gp84oGdqxg+FHLSNEdQXrPT3B2fEDkeDndd6qfvxkS5s1WYg/7DaYhGLEtiy/FspKU8mepNGUrns5kMmQMvjEn96UVUn29AT5CeZW93dhOWY4IXaijYZgU5p08yWJm/zjGDRVXACqn3N65+nlBu25KHwNmt4faAjvZpxvrAgMBAAECgYEAgZgkYAdBGE2cs92Gh0aamx8ddlANao/VMWBkRKct55YzykmglA9D6lbVCgUjP639TcLfCDqsD0j4At1AK3Mqcy8BAqV6Lm6PTP8vsNiKNRQAFjgIYmhhKUvxDuy8BYgsW8HSeZyb1W5xlu+/CQoxW0d1CRr1a3t2zJm5bbkeaWECQQDyt4WYKxuLQxUGKlraC/z3Cf47A/uEGMVYypgycqeJccCII3KrM8s8EQ3pBOPtCrA2b7McDVu0wNN5v1cyNk0DAkEArmHrP3EPuuOvudsfxDAsMjcUz1ZHHPvznyMo61vRj0CwV3Jqn4p9rC/H2cY+oRIBHSerCJnKdJDuo9OqThi8+QJBAM2Jj/4+cwLJeeJQt8LyZ/OjaMD9LF6+w0/fsGb4JNwFki83JYHJSI/DOW5cj89KP9K5YIme3kwBBpSQ7fw9c5UCQQCaVUsw4M19KBnUMZzRs5jJ8HnYbpGNk2cwBpwmgSLc1/G50yeOf7Ft/POxR4USZK7bsMnsWMAXnlW2ZJSrfbVxAkEA1eeAI3oFge1xMLSEH/3KJKyup9G6wKYN5gzlfCEPmTi46+TfmVtjM2lln1gg6OWVvjzyjJIns96dEES+o8Y1Dw==';

// 加密
export function encrypt(txt: string): any {
  const encryptor = new JSEncrypt();
  encryptor.setPublicKey(publicKey); // 设置公钥
  return encryptor.encrypt(txt); // 对数据进行加密
}

// 解密
export function decrypt(txt: string): any {
  const encryptor = new JSEncrypt();
  encryptor.setPrivateKey(privateKey); // 设置私钥
  return encryptor.decrypt(txt); // 对数据进行解密
}
